package com.blt.car.me.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.blt.car.R;
import com.blt.car.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import blt.app_core.api.journey.bean.TravelOrder;

/**
 * Created by xgp on 2017/6/29.
 */

public class BillDetailAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<TravelOrder> travelOrderList;

    public BillDetailAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        travelOrderList = new ArrayList<>();
    }


    @Override
    public int getCount() {
        return travelOrderList.size() ;
    }

    @Override
    public Object getItem(int position) {
        return travelOrderList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if (view == null) {
            view = inflater.inflate(R.layout.item_bill_detail, parent, false);
        }
        TextView startSite = (TextView) view.findViewById(R.id.item_bill_detail_from_site);
        TextView endSite = (TextView) view.findViewById(R.id.item_bill_detail_finish_site);
        TextView startTime = (TextView) view.findViewById(R.id.item_bill_detail_from_time);
        TextView plat = (TextView) view.findViewById(R.id.item_bill_detail_finish_time);
        TextView amount = (TextView) view.findViewById(R.id.item_bill_detail_amount);
        TravelOrder order = travelOrderList.get(position);


        String start = order.start.split("-")[1];
        startSite.setText(start);
        String end = order.end.split("-")[1];
        endSite.setText(end);
        startTime.setText(StringUtils.getDay(order.startTime));
        plat.setText(order.carNo);
        amount.setText(order.amount + "元");
        return view;
    }


    public void add(List<TravelOrder> data) {
        travelOrderList.clear();
        travelOrderList.addAll(data);
        notifyDataSetChanged();
    }
}
